package com.gd.iot.energy.controller.datamanage;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.consts.SystemConsts;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.datamanage.vo.RemotePageVO;
import com.gd.iot.energy.service.systemadmin.AreaArchivesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 远程控制
 *
 * @author kris
 * @date 2020/8/28 0028 11:08
 */
@Api(value = "数据管理-数据采集-数据查询-远程控制", tags = "数据管理-数据召测-数据查询-远程控制")
@RestController
@RequestMapping("/admin/remote")
public class RemoteControlController {

    @Autowired
    private AreaArchivesService areaArchivesService;

    @ApiOperation("远程控制分页列表")
    @SystemLogRecordMonitor("远程控制分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerPhone", value = "手机号码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getRemotePageVO")
    public ResponseEntity<PageVO<RemotePageVO>> getReadMeterPageVO(
            @RequestParam(value = "customerName", required = false) String customerName,
            @RequestParam(value = "customerPhone", required = false) String customerPhone,
            @RequestParam(value = "areaId", required = false) Integer areaId,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(value = "orderColumn", required = false, defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType", required = false, defaultValue = "desc") String orderType
    ) {

        PageVO<RemotePageVO> pageVO = areaArchivesService.getCurrentUserArchivesPage(customerName, customerPhone,
                areaId, pageSize, pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("开阀")
    @SystemLogRecordMonitor("开阀")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/open")
    public ResponseEntity<PageVO<RemotePageVO>> open(
            @RequestParam(value = "id", required = true) String id
    ) {
        areaArchivesService.open(id);
        return new ResponseEntity<>();
    }

    @ApiOperation("关阀")
    @SystemLogRecordMonitor("关阀")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/close")
    public ResponseEntity<PageVO<RemotePageVO>> close(
            @RequestParam(value = "id", required = true) String id
    ) {

        areaArchivesService.close(id);
        return new ResponseEntity<>();
    }

    @ApiOperation("批量关阀")
    @SystemLogRecordMonitor("批量关阀")
    @PostMapping("/multiClose")
    public ResponseEntity<PageVO<RemotePageVO>> getReadMeterPageVO(@RequestBody List<Long> ids) {

        areaArchivesService.multiOperate(ids, SystemConsts.OperateValveStateEnum.CLOSE.value);
        return new ResponseEntity<>();
    }
}
